CLI: Add VT Support library and update tests/callbacks to use it#40710
CLI: Add VT Support library and update tests/callbacks to use it#40710dkbennett wants to merge 14 commits into
Conversation
There was a problem hiding this comment.
Pull request overview
This PR introduces a shared VT (virtual terminal) support library under src/windows/common to centralize VT sequence constants/construction and console-mode RAII helpers, then updates WSLC callbacks and tests to consume the shared implementation (removing the prior WSLC-local ChangeTerminalMode.h).
Changes:
- Added
wsl::windows::common::vtVT sequence helpers, stream/concat operators, and console-mode RAII helpers (VTSupport.h/.cpp) and wired them into the common build. - Migrated WSLC image progress/build callbacks away from WSLC-local VT definitions to the shared VT support.
- Updated WSLC E2E helpers and added a new unit test suite validating VT sequences and console-mode helpers.
Reviewed changes
Copilot reviewed 12 out of 12 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
| test/windows/wslc/WSLCCLIVTSupportUnitTests.cpp | Adds new unit tests covering VT sequences and console-mode RAII helpers. |
| test/windows/wslc/e2e/WSLCExecutor.h | Adds Sequence overloads for stdout/stderr expectations in interactive sessions. |
| test/windows/wslc/e2e/WSLCExecutor.cpp | Adjusts formatting/expectations to use Sequence-based constants. |
| test/windows/wslc/e2e/WSLCE2EHelpers.h | Replaces ad-hoc VT macros with shared VTSupport sequences and helpers. |
| src/windows/wslc/services/ImageProgressCallback.h | Switches includes and member types to wsl::windows::common::vt helpers. |
| src/windows/wslc/services/ImageProgressCallback.cpp | Uses shared cursor-movement sequences instead of raw escape literals. |
| src/windows/wslc/services/ChangeTerminalMode.h | Removes WSLC-local cursor/VT RAII helpers (superseded by common VTSupport). |
| src/windows/wslc/services/BuildImageCallback.h | Switches to shared VT enablement helper; minor type adjustments for line counts. |
| src/windows/wslc/services/BuildImageCallback.cpp | Replaces raw escape formatting with shared VT sequences and stream composition. |
| src/windows/common/VTSupport.h | Adds new public VT support API (sequences, operators, and RAII helpers). |
| src/windows/common/VTSupport.cpp | Implements VT constants/builders and DA1 parsing. |
| src/windows/common/CMakeLists.txt | Adds VTSupport sources/headers to the windows/common build. |
OneBlue
left a comment
There was a problem hiding this comment.
LGTM, I think there's a few things that we simplify, but this design looks great !
|
|
||
| ChangeTerminalMode(HANDLE console, bool cursorVisible) : m_console(console) | ||
| { | ||
| if (!wsl::windows::common::wslutil::IsConsoleHandle(console)) |
There was a problem hiding this comment.
nit: Since we have a .cpp file, I would have a preference for moving the implementation of these methods to the .cpp, so we don't need to re-compile them every time they're included
|
|
||
| // operator<< for stream output. | ||
| // Widens the narrow sequence bytes (all ASCII) into a wide string for wostream output. | ||
| inline std::wostream& operator<<(std::wostream& o, const Sequence& s) |
There was a problem hiding this comment.
I'm guessing the objective of those is to use std::wcout, but for our usecase I would recommend to keep using the WriteConsoleW() mecanism since it's significantly faster.
| using namespace wsl::windows::common::vt; | ||
|
|
||
| auto ImageProgressCallback::MoveToLine(SHORT line) | ||
| void ImageProgressCallback::WriteTerminal(std::wstring_view content) const |
There was a problem hiding this comment.
Given that we're already defining this method in BuildImageCallback, I'd recommend factoring this method and moving it out to wslutil .
At some point, I think WSL should also move to it, but let's do that in a future change
|
|
||
| // operator<< for stream output. | ||
| // Widens the narrow sequence bytes (all ASCII) into a wide string for wostream output. | ||
| inline std::wostream& operator<<(std::wostream& o, const Sequence& s) |
There was a problem hiding this comment.
I'm guessing that this was originally designed to use std::wcout to actually write to the console, but in wslc's case, I would recommend not using std::wcout, but directly calling into WriteTerminal.
Maybe we could simplify a bit by directly using Get() when we print the sequence to the terminal (and we could also use this in the tests).
That would allow us to get rid of operator<< + string / wstring methods (our version of std::format() automatically handles string <-> wstring conversions)
Summary of the Pull Request
This is a foundational addition of VT support classes, wrappers, and constants to make working with VT sequences consistent and simpler without having to deal with the actual sequences and restoration. It removes the old ChangeTerminalMode.h and rolls that into the new VTSupport.h and cpp. This is added under windows/common so it can be utilized by more than just the CLI, but the unit tests are in with the CLI.
This should also help alleviate some other pulls where VT sequences are being defined in multiple locations, and also serves as a foundation for enhanced VT support in the CLI.
PR Checklist
Detailed Description of the Pull Request / Additional comments
Validation Steps Performed